package com.handydata.antifraud.web;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.handydata.antifraud.bo.datacalllogs.DataCallLogsBeanBO;
import com.handydata.antifraud.bo.datacalllogs.DataCallLogsReqBO;
import com.handydata.antifraud.bo.datacalllogs.DataCallLogsResBO;
import com.handydata.antifraud.bo.orderbaseinfo.OrderBaseInfoBeanBO;
import com.handydata.antifraud.bo.orderbaseinfo.OrderBaseInfoReqBO;
import com.handydata.antifraud.bo.orderbaseinfo.OrderBaseInfoResBO;
import com.handydata.antifraud.bo.orderreturninfo.OrderReturnInfoReqBO;
import com.handydata.antifraud.channel.inbound.DataReceiver;
import com.handydata.antifraud.common.constant.DataSourceCode;
import com.handydata.antifraud.crypt.MessageCryptoHandler;
import com.handydata.antifraud.enums.RiskFromEnum;
import com.handydata.antifraud.enums.RiskReturnEnum;
import com.handydata.antifraud.service.AlarmInfoService;
import com.handydata.antifraud.service.DataCallLogsService;
import com.handydata.antifraud.service.OrderBaseInfoService;
import com.handydata.antifraud.service.OrderReturnInfoService;
import com.handydata.antifraud.to.dap.*;
import com.handydata.antifraud.util.DateUtil;
import com.handydata.antifraud.util.encrypt.Base64Utils;
import com.handydata.antifraud.util.encrypt.DesUtils;
import com.handydata.antifraud.util.encrypt.Md5Utils;
import com.handydata.antifraud.util.encrypt.RSACoderUtils;
import com.handydata.antifraud.vo.orderbaseinfo.CreateOrderBaseInfoReqVO;
import com.handydata.antifraud.ws.dap.*;
import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.exception.SysException;
import com.handydata.common.util.RedisKey;
import com.handydata.common.util.RedisUtil;
import com.handydata.common.web.AbsController;

import io.netty.util.internal.StringUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;


@RequestMapping("/shrisk")
@RestController
@Slf4j
public class DataTransferController extends AbsController{

	@Autowired
	private DataReceiver dataReceiver;
	@Autowired
	private OrderBaseInfoService orderBaseInfoService;
	@Autowired
	private MessageCryptoHandler messageCryptoHandler;
	@Autowired
	private DataCallLogsService dataCallLogsService;
	@Autowired
	private AntiFraudBlackListWsServiceImpl antiFraudBlackListWsService;
	@Autowired
	private OwnerShipWsServiceImpl ownerShipWsServiceImpl;
	@Autowired
	private CisReportWsServiceImpl cisReportWsServiceImpl;
	@Autowired
	private OperatorElementWsServiceImpl operatorElementWsServiceImpl;
	@Autowired
	private OrderReturnInfoService orderReturnInfoService;
	@Autowired
	private DataZhiChengAfuScoreWsServiceImpl dataZhiChengAfuScoreWsServiceImpl;
	@Autowired
	private DataTianChuangBlacklistWsServiceImpl dataTianChuangBlacklistWsServiceImpl;
	@Autowired
	private GpsShipWsServiceImpl gpsShipWsServiceImpl;
	@Autowired
	private DataTanZhiInfoWsServiceImpl dataTanZhiInfoWsServiceImpl;
	@Autowired
	private DataYouBenWsServiceImpl dataYouBenWsServiceImpl;
	@Autowired
	private BaiRongWsServiceImpl baiRongWsServiceImpl;
	@Autowired
	private ALiYunWsServiceImpl aLiYunWsServiceImpl;
	@Autowired
	private HlzBin13ScoreWsServiceImpl hlzBin13ScoreWsServiceImpl;
	@Autowired
	private HlzBin11ScoreWsServiceImpl hlzBin11ScoreWsServiceImpl;
	@Autowired
	private TengxunYunWsServiceImpl tengXunYunWsServiceImpl;
	@Autowired
	private WoXinScoreWsServiceImpl woXinScoreWsServiceImpl;
	@Autowired
	private ZhiRenScoreXFWDXWsServiceImpl zhiRenScoreWsServiceImpl;
	@Autowired
	private AFuScoreWsServiceImpl aFuScoreWsServiceImpl;
	@Autowired
	private XinYiSouLinLangScoreWsServiceImpl xinYiSouScoreWsServiceImpl;
	@Autowired
	private HuaDaoScoreServiceImpl huaDaoScoreServiceImpl;
	@Autowired	
	private ZhiRenScoreXFDJWsServiceImpl zhiRenScoreXFDJWsServiceImpl;
	@Autowired
	private DataDianHuaBangWsServiceImpl dataDianHuaBangWsServiceImpl;
	@Autowired
	private ZhiRenScoreQZFWsServiceImpl zhiRenScoreQZFWsServiceImpl;
	@Autowired
	private ZhiRenScoreXFWDXWsServiceImpl zhiRenScoreXFWDXWsServiceImpl;
	@Autowired
	private XinYiSouMingMouScoreWsServiceImpl xinYiSouMingMouScoreWsServiceImpl;
	@Autowired
	private XinYiSouLinLangScoreWsServiceImpl xinYiSouLinLangScoreWsServiceImpl;
	@Autowired
	private JingZongThreeFactorsWsServiceImpl jingZongThreeFactorsWsServiceImpl;
	@Autowired
	private DianHuaBangThreeFactorsWsServiceImpl dianHuaBangThreeFactorsWsServiceImpl;
	@Autowired
	private HuaDaoBlackListWsServiceImpl huaDaoBlackListWsServiceImpl;
	@Autowired
	private HuaDaoShortTermRiskWsServiceImpl huaDaoShortTermRiskWsServiceImpl;
	@Autowired
	private HuaDaoCreditScoreWsServiceImpl huaDaoCreditScoreWsServiceImpl;
	@Autowired
	private HuaDaoMultiWsServiceImpl huaDaoMultiWsServiceImpl;
	@Autowired
	private HuaDaoFraudModelWsServiceImpl huaDaoFraudModelWsServiceImpl;

	@Autowired
	private AlarmInfoService alarmInfoService;

    @Value("${risk.shbank.private-key}")
    private String riskShbankPrivateKey;
    @Value("${risk.shbank.public-key}")
    private String riskShbankPublicKey;
	@Autowired
	private RedisUtil redisUtil;
	
	/**
	 * 上行推送数据
	 * @param reqData
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@ApiOperation(value="上行推送数据", notes="上行推送数据")
	@ApiImplicitParam(name = "req", value = "上行推送数据请求对象", required = true, dataType = "ShbankPushDataReqVO")
	@RequestMapping(value = "/serv", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")
	//@PostMapping("/serv")
	public String receiveData(@RequestBody(required=false) String reqData) {
		log.info("上行推送数据请求数据：{}", reqData);
		String result;
		try {
			// 测试数据加密
//			reqData = encrypt(reqData);
			// 请求数据解密
			String[] arry = reqData.split("\\|");
			if (StringUtil.isNullOrEmpty(reqData) || reqData.trim().length() == 0 || arry.length != 3) {
				result = handleResult("0", RiskReturnEnum.DATA_FORMAT_ERROR.getCode(), RiskReturnEnum.DATA_FORMAT_ERROR.getText());
			} else{
				Map<String, Object> clearTextMap = JSONObject.parseObject(decrypt1(arry));
				log.info("上行推送数据请求数据解密结果：{}", clearTextMap);
				//推送数据参数校验
				//Map<String, Object> clearTextMap = JSONObject.parseObject(reqData);
				shbankPushDataValidate(clearTextMap);
				CreateOrderBaseInfoReqVO createOrderBaseInfoReqVO = CommonBeanConvertor.convert(clearTextMap, CreateOrderBaseInfoReqVO.class);
				Map<String, String> map = (Map<String, String>) JSONObject.toJSON(clearTextMap.get("logicData"));
				if (StringUtils.equals("FLOW015", map.get("custTypeCode"))) {
					String[] pro = map.get("province").replace("，", ",").split(",");
					if(pro.length > 2){
						map.put("provinceFlow015", pro[0]);
						map.put("cityFlow015", pro[1]);
					}
				}
				createOrderBaseInfoReqVO.setName(map.get("name"));
				createOrderBaseInfoReqVO.setPhoneNum(map.get("phoneNum"));
				createOrderBaseInfoReqVO.setIdCard(map.get("idCard"));
				createOrderBaseInfoReqVO.setOrderId((String)clearTextMap.get("orderId"));
				createOrderBaseInfoReqVO.setProductCode((String)(clearTextMap.get("productCode")));
				map.put("orderId",(String)clearTextMap.get("orderId"));
				createOrderBaseInfoReqVO.setMerCode((String)(clearTextMap.get("merCode")));
				createOrderBaseInfoReqVO.setRecieveData(JSONObject.toJSONString(map));
				// 调用接口处理订单数据
				String receiveResult = dataReceiver.receiveData(createOrderBaseInfoReqVO);
				// 返回结果
				if ("0000".equals(receiveResult)) {
					result = handleResult("1", RiskFromEnum.SHBANK_RECEIVE_DATA_OK.getCode(), RiskFromEnum.SHBANK_RECEIVE_DATA_OK.getText());
				} else {
					result = handleResult("0", RiskReturnEnum.DATA_FORMAT_ERROR.getCode(), RiskReturnEnum.DATA_FORMAT_ERROR.getText());
				}
			}
		} catch (Exception e) {
			log.error("上海银行数据推送接口调用异常", e);
			result = handleResult("0", "9999", "上海银行数据推送接口调用异常：" + e.getMessage());
		}
		log.info("上行推送接口返回结果：{}", result);
		return result;
	}
	/**
	 * 上行推送数据
	 * @param reqData
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@ApiOperation(value="上行推送数据1", notes="上行推送数据1")
	@ApiImplicitParam(name = "req", value = "上行推送数据请求对象", required = true, dataType = "ShbankPushDataReqVO")
	@RequestMapping(value = "/serv1", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")
	//@PostMapping("/serv1")
	public String receiveData1(@RequestBody(required=false) String reqData) {
		log.info("上行推送数据请求数据：{}", reqData);
		String result;
		try {
			// 测试数据加密
//			reqData = encrypt(reqData);
			// 请求数据解密
//			String[] arry = reqData.split("\\|");
//			if (StringUtil.isNullOrEmpty(reqData) || reqData.trim().length() == 0 || arry.length != 3) {
//				result = handleResult("0", RiskReturnEnum.DATA_FORMAT_ERROR.getCode(), RiskReturnEnum.DATA_FORMAT_ERROR.getText());
//			} else
//
//			{
//				Map<String, Object> clearTextMap = JSONObject.parseObject(decrypt1(arry));
//				log.info("上行推送数据请求数据解密结果：{}", clearTextMap);
//				推送数据参数校验
				Map<String, Object> clearTextMap = JSONObject.parseObject(reqData);

				shbankPushDataValidate(clearTextMap);

				CreateOrderBaseInfoReqVO createOrderBaseInfoReqVO = CommonBeanConvertor.convert(clearTextMap, CreateOrderBaseInfoReqVO.class);
				Map<String, String> map = (Map<String, String>) JSONObject.toJSON(clearTextMap.get("logicData"));

				if (StringUtils.equals("FLOW015", map.get("custTypeCode"))) {
					String[] pro = map.get("province").replace("，", ",").split(",");
					if(pro.length > 2){
						map.put("provinceFlow015", pro[0]);
						map.put("cityFlow015", pro[1]);
					}
				} 
				createOrderBaseInfoReqVO.setName(map.get("name"));
				createOrderBaseInfoReqVO.setPhoneNum(map.get("phoneNum"));
				createOrderBaseInfoReqVO.setIdCard(map.get("idCard"));
				createOrderBaseInfoReqVO.setOrderId((String)clearTextMap.get("orderId"));
				createOrderBaseInfoReqVO.setProductCode((String)(clearTextMap.get("productCode")));
				map.put("orderId",(String)clearTextMap.get("orderId"));
				createOrderBaseInfoReqVO.setMerCode((String)(clearTextMap.get("merCode")));
				createOrderBaseInfoReqVO.setRecieveData(JSONObject.toJSONString(map));
				// 调用接口处理订单数据
				String receiveResult = dataReceiver.receiveData(createOrderBaseInfoReqVO);
				// 返回结果
				if ("0000".equals(receiveResult)) {
					result = handleResult("1", RiskFromEnum.SHBANK_RECEIVE_DATA_OK.getCode(), RiskFromEnum.SHBANK_RECEIVE_DATA_OK.getText());
				} else {
					result = handleResult("0", RiskReturnEnum.DATA_FORMAT_ERROR.getCode(), RiskReturnEnum.DATA_FORMAT_ERROR.getText());
				}
//			}
		} catch (Exception e) {
			log.error("上海银行数据推送接口调用异常", e);
			result = handleResult("0", "9999", "上海银行数据推送接口调用异常：" + e.getMessage());
		}
		log.info("上行推送接口返回结果：{}", result);
		return result;
	}
	 /**
	  * 风控结果查询
	  */
	
	@ApiOperation(value="风控结果查询", notes="风控结果查询")
	@ApiImplicitParam(name = "req", value = "风控结果查询请求对象", required = true, dataType = "CreateDataCallLogsReqVO")
	//@PostMapping("/getOrderIdResult")
	@RequestMapping(value = "/getOrderIdResult", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")
	public String queryRiskResultByShbank(@RequestBody(required=false) String reqData) {
		log.info("风控结果查询请求参数： {}", reqData);
		String result;
		String orderId = null;
		OrderReturnInfoReqBO orderReturnInfoReqBO = new OrderReturnInfoReqBO();
		try { 
			String queryResult;
			// 请求数据解密
			String[] arry = reqData.split("\\|");
			if (StringUtil.isNullOrEmpty(reqData) || reqData.trim().length() == 0 || arry.length != 3) {
				return handleResult("0", RiskReturnEnum.DATA_FORMAT_ERROR.getCode(), RiskReturnEnum.DATA_FORMAT_ERROR.getText());
			} else {
				JSONObject j = JSONObject.parseObject(decrypt1(arry));
				log.info("风控结果查询请求参数解密结果： {}", j.toJSONString());
    			orderId = j.getString("orderId");
				// 参数校验
				queryRiskDataValidate(orderId);
				// 根据订单号查询订单信息
				OrderBaseInfoReqBO orderBaseInfoReqBO = new OrderBaseInfoReqBO();
				orderBaseInfoReqBO.setOrderId(orderId);
				OrderBaseInfoResBO orderBaseInfoResBO = orderBaseInfoService.queryOrderBaseInfo(orderBaseInfoReqBO);
				if (orderBaseInfoResBO != null && orderBaseInfoResBO.getResultList() != null && !orderBaseInfoResBO.getResultList().isEmpty()) {
					OrderBaseInfoBeanBO bo = orderBaseInfoResBO.getResultList().get(0);
					if (!StringUtils.isEmpty(bo.getSendMsg()) && 
						("4".equals(bo.getProcessState()) || "2".equals(bo.getProcessState()) || "5".equals(bo.getProcessState()))) {
						queryResult=bo.getSendMsg();// 订单处理状态为处理成功或返回成功&&处理结果不为空
					} else if ("1".equals(bo.getProcessState()) || "0".equals(bo.getProcessState())){
						log.info("上行查询风控结果接口返回:{}", "订单号：" + orderId + "风控模型执行中");
						return handleResult("0", RiskReturnEnum.RISK_MODEL_IN_EXEC.getCode(), RiskReturnEnum.RISK_MODEL_IN_EXEC.getText());
					} else {
						log.info("上行查询风控结果接口返回:{}", "订单号：" + orderId + "风控决策系统异常");
						return handleResult("0", RiskReturnEnum.RISK_SYSTEM_ERROR.getCode(), RiskReturnEnum.RISK_SYSTEM_ERROR.getText());
					}
				} else {
					log.info("上行查询风控结果接口返回:{}", "订单号：" + orderId + "无此订单信息");
					return handleResult("0", RiskReturnEnum.NO_ORDER_ERROR.getCode(), RiskReturnEnum.NO_ORDER_ERROR.getText());
				}
			}
			// 记录订单操作日志表
			orderReturnInfoReqBO.setOrderId(orderId);
			orderReturnInfoReqBO.setOperateType("2");
			orderReturnInfoReqBO.setOperateStatus("1");
			orderReturnInfoReqBO.setOperateTime(new Date());
			orderReturnInfoService.createOrderReturnInfo(orderReturnInfoReqBO);
			log.info("风控结果数据给上行-加密前参数:{}", queryResult);
			// 返回信息加密
			result = encrypt1(queryResult);
			log.info("风控结果数据给上行-加密后参数:{}", result);
		} catch (Exception e) { 
			log.error("调用风控结果查询接口异常:{}", e.getMessage());
			// 记录订单操作日志表
			orderReturnInfoReqBO.setOrderId(orderId);
			orderReturnInfoReqBO.setOperateType("2");
			orderReturnInfoReqBO.setOperateStatus("2");
			orderReturnInfoReqBO.setOperateTime(new Date());
			orderReturnInfoService.createOrderReturnInfo(orderReturnInfoReqBO);
			result = handleResult("0", "9999", "上海银行数据推送接口调用异常：" + e.getMessage());
		}
		return result; 
	}
	 
	 /**
	  * 第三方数据源结果查询
	  */
	@ApiOperation(value="第三方数据源结果查询", notes="第三方数据源结果查询")
	//@PostMapping("/faceData")
	@RequestMapping(value = "/faceData", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")

	public String faceData(@RequestBody(required=false) String reqData){
		log.info("第三方数据源结果查询请求参数： {}", reqData);
		String encryptMsg;
		try {
			String result;
			// 测试数据加密(postman明文请求)
//			reqData = encrypt1(reqData);
			String[] arry = reqData.split("\\|");
			if (StringUtil.isNullOrEmpty(reqData) || reqData.trim().length() == 0 || arry.length != 3) {
				return handleResult("0", RiskReturnEnum.DATA_FORMAT_ERROR.getCode(), RiskReturnEnum.DATA_FORMAT_ERROR.getText());
			} else {	
				// 请求数据解密
				JSONObject j = JSONObject.parseObject(decrypt1(arry));
				log.info("风控结果查询请求参数解密结果： {}", j);
    			String orderId = j.getString("orderId");
				// 参数校验
				queryRiskDataValidate(orderId);
				// 根据订单号查询第三方数据源查询结果
				DataCallLogsReqBO dataCallLogsReqBO = new DataCallLogsReqBO();
				dataCallLogsReqBO.setOrderId(orderId);
				DataCallLogsResBO dataCallLogsResBO = dataCallLogsService.queryDataCallLogs(dataCallLogsReqBO);
				if (dataCallLogsResBO != null && dataCallLogsResBO.getResultList() != null && !dataCallLogsResBO.getResultList().isEmpty()) {
					JSONObject json = new JSONObject();
					json.put("orderId", orderId);
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
					Date date = new Date();
					String dateStr = sdf.format(date);
					json.put("dateTime", dateStr);
					JSONArray jsona = new JSONArray();
					for (DataCallLogsBeanBO dataCall : dataCallLogsResBO.getResultList()) {
						JSONObject json2 = new JSONObject();
						if (!StringUtil.isNullOrEmpty(enumConert().get(dataCall.getDataType()))) {
							json2.put(enumConert().get(dataCall.getDataType()), dataCall.getResult());
						}
						jsona.add(json2);
					}
					json.put("faces", jsona);
					result = json.toJSONString();
				} else {
					log.info("上行调用第三方数据源结果查询接口返回:{}", "订单号：" + orderId + "无此订单信息");
					return handleResult("0", RiskReturnEnum.NO_ORDER_ERROR.getCode(), RiskReturnEnum.NO_ORDER_ERROR.getText());
				}
				log.info("第三方数据源结果数据给上行-加密前参数:{}", result);
				// 返回信息加密
				encryptMsg = encrypt1(result);
				log.info("第三方数据源结果给上行-加密后参数:{}", encryptMsg);
			}
		} catch (Exception e) { 
			log.error("上行调用第三方数据源结果查询异常:{}", e);
			return handleResult("0", "9999", "上行调用第三方数据源结果查询异常：" + e.getMessage());
		}
		return encryptMsg;
	}

	 /**
	  * 查询第三方入模字段详情
	  */
	@ApiOperation(value="查询第三方入模字段详情", notes="查询第三方入模字段详情")
	//@PostMapping("/getThirdData")
	@RequestMapping(value = "/getThirdData", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")
	public String getThirdData(@RequestBody(required=false) String reqData){
		log.info("查询第三方入模字段详情请求参数： {}", reqData);
		String encryptMsg;
		try {
			String result;
			// 测试数据加密(postman明文请求)
//			reqData = encrypt(reqData);
			// 请求数据解密
			String[] arry = reqData.split("\\|");
			if (StringUtil.isNullOrEmpty(reqData) || reqData.trim().length() == 0 || arry.length != 3) {
				return handleResult("0", RiskReturnEnum.DATA_FORMAT_ERROR.getCode(), RiskReturnEnum.DATA_FORMAT_ERROR.getText());
			} else {
				JSONObject j = JSONObject.parseObject(decrypt1(arry));
				log.info("查询第三方入模字段详情参数解密结果： {}", j.toJSONString());
    			String orderId = j.getString("orderId");
				// 参数校验
				queryRiskDataValidate(orderId);
				// 根据订单号查询第三方数据源查询结果
				DataCallLogsReqBO dataCallLogsReqBO = new DataCallLogsReqBO();
				dataCallLogsReqBO.setOrderId(orderId);
				DataCallLogsResBO dataCallLogsResBO = dataCallLogsService.queryDataCallLogs(dataCallLogsReqBO);
				if (dataCallLogsResBO != null && dataCallLogsResBO.getResultList() != null && !dataCallLogsResBO.getResultList().isEmpty()) {
					JSONObject json = new JSONObject();
					json.put("orderId", orderId);
					json.put("dateTime", DateUtil.now18());
					PropellingShDetailData thirdCommonData = getThirdCommonData(dataCallLogsResBO.getResultList());
					json.put("propellingShDetailData", thirdCommonData);
					result = json.toJSONString();
				} else {
					log.info("上行调用查询第三方入模字段详情查询接口返回:", "订单号：" + orderId + "无此订单信息");
					return handleResult("0", RiskReturnEnum.NO_ORDER_ERROR.getCode(), RiskReturnEnum.NO_ORDER_ERROR.getText());
				}
				log.info("查询第三方入模字段详情结果数据给上行-加密前参数:{}", result);
				// 返回信息加密
				encryptMsg = encrypt1(result);
				log.info("查询第三方入模字段详情结果数据给上行-加密后参数:{}", encryptMsg);
			}
		} catch (Exception e) { 
			log.error("上行调用查询第三方入模字段详情查询异常:", e.getMessage());
			return handleResult("0", "9999", "上行调用查询第三方入模字段详情查询异常：" + e.getMessage());
		}
		return encryptMsg;
	}
	 
	/**
	 * 上海银行数据推送参数校验
	 * 
	 * @param map
	 */
	public void shbankPushDataValidate(Map<String, Object> map) {
		Assert.isTrue(!StringUtils.isEmpty(String.valueOf(map.get("orderId"))), "订单号为空");
		Assert.isTrue(!StringUtils.isEmpty(String.valueOf(map.get("merCode"))), "商户号为空");
		Assert.isTrue(!StringUtils.isEmpty(String.valueOf(map.get("productCode"))), "产品号为空");
		//Assert.isTrue(!StringUtils.isEmpty(String.valueOf(map.get("shPrivIp"))), "上行推送数据服务器IP为空");
		Assert.isTrue(!StringUtils.isEmpty(String.valueOf(map.get("apiKey"))), "ApiKey为空");
		Assert.isTrue(null != map.get("logicData"), "设备信息及用户输入信息为空");
	}
	
	/**
	 * 测试数据平台接口
	 */
	@PostMapping("/getDataPlatform")
	public void getDataPlatform(@RequestBody String reqData){
		
//		HuaDaoFraudModelReqTO reqT52 = new HuaDaoFraudModelReqTO();
//		JSONObject jo52 = JSONObject.parseObject(reqData);
//		reqT52.setPhoneNum(jo52.getString("phoneNum"));
//		reqT52.setName(jo52.getString("name"));
//		reqT52.setIdCard(jo52.getString("idCard"));
//		reqT52.setOrderId(jo52.getString("orderId"));
//		HuaDaoFraudModelResTO resT52 = huaDaoFraudModelWsServiceImpl.query(reqT52);
//		System.out.println("华道反欺诈模型===================:" + JSONObject.toJSONString(resT52));
		
//		OperatorElementReqTO reqT51 = new OperatorElementReqTO();
//		JSONObject jo51 = JSONObject.parseObject(reqData);
//		reqT51.setPhoneNum(jo51.getString("phoneNum"));
//		reqT51.setName(jo51.getString("name"));
//		reqT51.setIdCard(jo51.getString("idCard"));
//		reqT51.setOrderId(jo51.getString("orderId"));
//		OperatorElementResTO resT51 = operatorElementWsServiceImpl.query(reqT51);
//		System.out.println("三要素验证===================:" + JSONObject.toJSONString(resT51));
		
//		DataZhiChengAfuScoreReqTO reqT50 = new DataZhiChengAfuScoreReqTO();
//		JSONObject jo50 = JSONObject.parseObject(reqData);
//		reqT50.setPhoneNum(jo50.getString("phoneNum"));
//		reqT50.setName(jo50.getString("name"));
//		reqT50.setIdCard(jo50.getString("idCard"));
//		reqT50.setOrderId(jo50.getString("orderId"));
//		DataZhiChengAfuScoreResTO resT40 = dataZhiChengAfuScoreWsServiceImpl.query(reqT50);
//		System.out.println("至诚阿福===================:" + JSONObject.toJSONString(resT40));
		
//		HuaDaoMultiReqTO reqT40 = new HuaDaoMultiReqTO();
//		JSONObject jo40 = JSONObject.parseObject(reqData);
//		reqT40.setPhoneNum(jo40.getString("phoneNum"));
//		reqT40.setName(jo40.getString("name"));
//		reqT40.setIdCard(jo40.getString("idCard"));
//		reqT40.setOrderId(jo40.getString("orderId"));
//		HuaDaoMultiResTO resT40 = huaDaoMultiWsServiceImpl.query(reqT40);
//		System.out.println("华道短周期风险等级===================:" + JSONObject.toJSONString(resT40));
//		
//		HuaDaoShortTermRiskReqTO reqT38 = new HuaDaoShortTermRiskReqTO();
//		JSONObject jo38 = JSONObject.parseObject(reqData);
//		reqT38.setPhoneNum(jo38.getString("phoneNum"));
//		reqT38.setName(jo38.getString("name"));
//		reqT38.setIdCard(jo38.getString("idCard"));
//		reqT38.setOrderId(jo38.getString("orderId"));
//		HuaDaoShortTermRiskResTO resT38 = huaDaoShortTermRiskWsServiceImpl.query(reqT38);
//		System.out.println("华道短周期风险等级===================:" + JSONObject.toJSONString(resT38));
//		
		HuaDaoBlackListReqTO reqTO37 = new HuaDaoBlackListReqTO();
		JSONObject jo37 = JSONObject.parseObject(reqData);
		reqTO37.setPhoneNum(jo37.getString("phoneNum"));
		reqTO37.setName(jo37.getString("name"));
		reqTO37.setIdCard(jo37.getString("idCard"));
		reqTO37.setOrderId(jo37.getString("orderId"));
		HuaDaoBlackListResTO resTO37 = huaDaoBlackListWsServiceImpl.query(reqTO37);
		System.out.println("华道黑名单===================:" + JSONObject.toJSONString(resTO37));
//		
//		HuaDaoCreditScoreReqTO reqTO39 = new HuaDaoCreditScoreReqTO();
//		JSONObject jo39 = JSONObject.parseObject(reqData);
//		reqTO39.setPhoneNum(jo39.getString("phoneNum"));
//		reqTO39.setName(jo39.getString("name"));
//		reqTO39.setIdCard(jo39.getString("idCard"));
//		reqTO39.setOrderId(jo39.getString("orderId"));
//		HuaDaoCreditScoreResTO resTO39 = huaDaoCreditScoreWsServiceImpl.query(reqTO39);
//		System.out.println("华道信用评分===================:" + JSONObject.toJSONString(resTO39));		
		
//		DianHuaBangThreeFactorsReqTO reqTO23 = new DianHuaBangThreeFactorsReqTO();
//		JSONObject jo23 = JSONObject.parseObject(reqData);
//		reqTO23.setIdCard(jo23.getString("idCard"));
//		reqTO23.setName((jo23.getString("name")));
//		reqTO23.setPhoneNum(jo23.getString("phoneNum"));
//		reqTO23.setOrderId(jo23.getString("orderId"));
//		DianHuaBangThreeFactorsResTO resTO23 = dianHuaBangThreeFactorsWsServiceImpl.query(reqTO23);
//		System.out.println("电话邦三要素===================:" + JSONObject.toJSONString(resTO23));
		
//		JingZongThreeFactorsReqTO reqTO22 = new JingZongThreeFactorsReqTO();
//		JSONObject jo22 = JSONObject.parseObject(reqData);
//		reqTO22.setIdCard(jo22.getString("idCard"));
//		reqTO22.setName((jo22.getString("name")));
//		reqTO22.setPhoneNum(jo22.getString("phoneNum"));
//		reqTO22.setOrderId(jo22.getString("orderId"));
//		JingZongThreeFactorsResTO resTO22 = jingZongThreeFactorsWsServiceImpl.query(reqTO22);
//		System.out.println("敬众三要素===================:" + JSONObject.toJSONString(resTO22));
		
//		ALiYunReqTO reqTO2 = new ALiYunReqTO();
//		JSONObject jo1 = JSONObject.parseObject(reqData);
//		reqTO2.setIdCard(jo1.getString("idCard"));
//		reqTO2.setName((jo1.getString("name")));
//		reqTO2.setPhoneNum(jo1.getString("phoneNum"));
//		reqTO2.setOrderId(jo1.getString("orderId"));
//		ALiYunResTO resTO2 = aLiYunWsServiceImpl.query(reqTO2);
//		System.out.println("aliyun===================:" + JSONObject.toJSONString(resTO2));
		
//		BaiRongReqTO reqTO3 = new BaiRongReqTO();
//		JSONObject jo3 = JSONObject.parseObject(reqData);
//		reqTO3.setIdCard(jo3.getString("idCard"));
//		reqTO3.setName((jo3.getString("name")));
//		reqTO3.setPhoneNum(jo3.getString("phone"));
//		reqTO3.setContactsPhone(jo3.getString("contactsPhone"));
//		reqTO3.setYearRange(jo3.getString("yearRange"));
//		String[] splits = jo3.getString("queryModule").split("-");
//		reqTO3.setAttr(splits[1]);
//		reqTO3.setQueryModule("");
//		reqTO3.setOrderId(jo3.getString("orderId"));
//		BaiRongResTO resTO3 = baiRongWsServiceImpl.query(reqTO3);
//		System.out.println("bairong===================:" + JSONObject.toJSONString(resTO3));
		
//		WoXinScoreReqTO reqTO = new WoXinScoreReqTO();
//		JSONObject jo = JSONObject.parseObject(reqData);
//		reqTO.setPhoneNum(jo.getString("phoneNum"));
//		reqTO.setOrderId(jo.getString("orderId"));
//		WoXinScoreResTO resTO = woXinScoreWsServiceImpl.query(reqTO);
//		System.out.println("沃信分===================:" + JSONObject.toJSONString(resTO));
//		log.info("沃信分接口返回结果：{}", JSONObject.toJSONString(resTO));
		
//		DataDianHuaBangReqTO reqTO5 = new DataDianHuaBangReqTO();
//		JSONObject jo5 = JSONObject.parseObject(reqData);
//		reqTO5.setIdCard(jo5.getString("idCard"));
//		reqTO5.setName((jo5.getString("name")));
//		reqTO5.setPhoneNum(jo5.getString("phoneNum"));
//		reqTO5.setOrderId(jo5.getString("orderId"));
//		DataDianHuaBangResTO resTO5 = dataDianHuaBangWsServiceImpl.query(reqTO5);
//		System.out.println("dianhuabang===================:" + JSONObject.toJSONString(resTO5));
//		HlzBin13ScoreReqTO reqTO6 = new HlzBin13ScoreReqTO();
//		JSONObject jo6 = JSONObject.parseObject(reqData);
//		reqTO6.setIdCard(jo6.getString("idCard"));
//		reqTO6.setName((jo6.getString("name")));
//		reqTO6.setPhoneNum(jo6.getString("phone"));
//		reqTO6.setOrderId(jo6.getString("orderId"));
//		HlzBin13ScoreResTO resTO6 = hlzBin13ScoreWsServiceImpl.query(reqTO6);
//		System.out.println("hlzBin13Score===================:" + JSONObject.toJSONString(resTO6));
		
//		HuaDaoScoreReqTO reqTO7 = new HuaDaoScoreReqTO();
//		JSONObject jo7 = JSONObject.parseObject(reqData);
//		reqTO7.setPhoneNum(jo7.getString("phoneNum"));
//		reqTO7.setName(jo7.getString("name"));
//		reqTO7.setIdCard(jo7.getString("idCard"));
//		reqTO7.setOrderId(jo7.getString("orderId"));
//		HuaDaoScoreResTO resTO7 = huaDaoScoreServiceImpl.query(reqTO7);
//		System.out.println("华道评分===================:" + JSONObject.toJSONString(resTO7));
		
//		ZhiRenScoreQZFReqTO reqTO8 = new ZhiRenScoreQZFReqTO();
//		JSONObject jo8 = JSONObject.parseObject(reqData);
//		reqTO8.setIdCard(jo8.getString("idCard"));
//		reqTO8.setName((jo8.getString("name")));
//		reqTO8.setPhoneNum(jo8.getString("phone"));
//		reqTO8.setOrderId(jo8.getString("orderId"));
//		ZhiRenScoreQZFResTO resTO8 = zhiRenScoreQZFWsServiceImpl.query(reqTO8);
//		System.out.println("zhiRenScoreQZF===================:" + JSONObject.toJSONString(resTO8));

//		ZhiRenScoreXFDJReqTO reqTO9 = new ZhiRenScoreXFDJReqTO();
//		JSONObject jo9 = JSONObject.parseObject(reqData);
//		reqTO9.setIdCard(jo9.getString("idCard"));
//		reqTO9.setName((jo9.getString("name")));
//		reqTO9.setPhoneNum(jo9.getString("phone"));
//		reqTO9.setOrderId(jo9.getString("orderId"));
//		ZhiRenScoreXFDJResTO resTO9 = zhiRenScoreXFDJWsServiceImpl.query(reqTO9);
//		System.out.println("zhiRenScoreXFDJ===================:" + JSONObject.toJSONString(resTO9));
		
//		ZhiRenScoreXFWDXReqTO reqTO10 = new ZhiRenScoreXFWDXReqTO();
//		JSONObject jo10 = JSONObject.parseObject(reqData);
//		reqTO10.setIdCard(jo10.getString("idCard"));
//		reqTO10.setName((jo10.getString("name")));
//		reqTO10.setPhoneNum(jo10.getString("phone"));
//		reqTO10.setOrderId(jo10.getString("orderId"));
//		ZhiRenScoreXFWDXResTO resTO10 = zhiRenScoreXFWDXWsServiceImpl.query(reqTO10);
//		System.out.println("zhiRenScoreXFWDX===================:" + JSONObject.toJSONString(resTO10));
		
//		DataTanZhiInfoReqTO reqTO4 = new DataTanZhiInfoReqTO();
//		JSONObject jo2 = JSONObject.parseObject(reqData);
//		reqTO4.setIdCard(jo2.getString("idCard"));
//		reqTO4.setName((jo2.getString("name")));
//		reqTO4.setPhoneNum(jo2.getString("phoneNum"));
//		reqTO4.setOrderId(jo2.getString("orderId"));
//		DataTanZhiInfoResTO resTO4 = dataTanZhiInfoWsServiceImpl.query(reqTO4);
//		System.out.println("tanzhi===================:" + JSONObject.toJSONString(resTO4));
	
		TengxunYunReqTO reqTO12 = new TengxunYunReqTO();
		JSONObject jo12 = JSONObject.parseObject(reqData);
		reqTO12.setIdCard(jo12.getString("idCard"));
		reqTO12.setName((jo12.getString("name")));
		reqTO12.setPhoneNum(jo12.getString("phone"));
		reqTO12.setOrderId(jo12.getString("orderId"));
		TengxunYunResTO resTO12 = tengXunYunWsServiceImpl.query(reqTO12);
		System.out.println("TengxunYun===================:" + JSONObject.toJSONString(resTO12));
		
//		XinYiSouScoreLinLangReqTO reqTO13 = new XinYiSouScoreLinLangReqTO();
//		JSONObject jo13 = JSONObject.parseObject(reqData);
//		reqTO13.setPhoneNum(jo13.getString("phoneNum"));
//		reqTO13.setName(jo13.getString("name"));
//		reqTO13.setIdCard(jo13.getString("idCard"));
//		reqTO13.setAttr(jo13.getString("attr"));
//		reqTO13.setOrderId(jo13.getString("orderId"));
//		XinYiSouLinLangScoreResTO resTO13 = xinYiSouLinLangScoreWsServiceImpl.query(reqTO13);
//		System.out.println("XinYiSouScoreLinLang===================:" + JSONObject.toJSONString(resTO13));
		
//		XinYiSouMingMouScoreReqTO reqTO14 = new XinYiSouMingMouScoreReqTO();
//		JSONObject jo14 = JSONObject.parseObject(reqData);
//		reqTO14.setPhoneNum(jo14.getString("phoneNum"));
//		reqTO14.setName(jo14.getString("name"));
//		reqTO14.setIdCard(jo14.getString("idCard"));
//		reqTO14.setAttr(jo14.getString("attr"));
//		reqTO14.setOrderId(jo14.getString("orderId"));
//		XinYiSouMingMouScoreResTO resTO14 = xinYiSouMingMouScoreWsServiceImpl.query(reqTO14);
//		System.out.println("XinYiSouScoreLinLang===================:" + JSONObject.toJSONString(resTO14));
		
//		AFuScoreReqTO reqTO15 = new AFuScoreReqTO();
//		JSONObject jo15 = JSONObject.parseObject(reqData);
//		reqTO15.setPhoneNum(jo15.getString("phoneNum"));
//		reqTO15.setName(jo15.getString("name"));
//		reqTO15.setIdCard(jo15.getString("idCard"));
//		reqTO15.setAttr(jo15.getString("attr"));
//		reqTO15.setOrderId(jo15.getString("orderId"));
//		AFuScoreResTO resTO15 = aFuScoreWsServiceImpl.query(reqTO15);
//		System.out.println("阿福查询===================:" + JSONObject.toJSONString(resTO15));

	}
	
	
	/**
	 * 风控结果信息查询
	 * @param orderId
	 */
	public static void queryRiskDataValidate(String orderId) {
		Assert.isTrue(!StringUtils.isEmpty(orderId), "订单号为空");
	}

	//	private String encrypt(Object payload) {
//        String desKey = RadomGenerator.random(24);
//        String json = payload instanceof String ? (String)payload : JSONUtil.convertJson(payload);
//        log.info("推送数据给上行-请求参数:{}", json);
//        CryptoReq crypto = CryptoReq.builder()
//                .desKey(desKey)
//                .content(json)
//                .build();
//        crypto.setPrivateKey(riskShbankPrivateKey);
//        boolean encodeCorrect = messageCryptoHandler.encode(crypto);
//        if(!encodeCorrect) {
//            String[] errs = crypto.getMsg().split("\\|");
//            throw new SysException(errs[0], errs[1]);
//        }
//        return crypto.getEncryptObject().toString();
//    }
	/**
	 * 发送给上行的数据---私钥加密
	 * @param param
	 * @return
	 */
	private String encrypt1(String param) {
		return getString(param, riskShbankPrivateKey);
	}

	private static String getString(String param, String riskShbankPrivateKey) {
		String result;
		try {
			log.info("encrypt1 private key {}", riskShbankPrivateKey);
			// 加密第一段数据
			String uuid = UUID.randomUUID().toString().replace("-", "");
			String rsaUuid = RSACoderUtils.encryptByPrivateKey(uuid, riskShbankPrivateKey);
			String base64RsaUuid = Base64Utils.encode(rsaUuid.getBytes());
			// 加密第二段数据
			byte[] desTxt = DesUtils.encrypt(param.getBytes(StandardCharsets.UTF_8), uuid.getBytes(StandardCharsets.UTF_8));
			String baseDesTxt = Base64Utils.encode(desTxt);
			// 加密第三段数据
			String md5Uuid = Md5Utils.md5ToHexStr(uuid);
			String base64Md5Uuid = Base64Utils.encode(md5Uuid.getBytes());
			result = base64RsaUuid + "|" + baseDesTxt + "|" + base64Md5Uuid;
		} catch (Exception e) {
			throw new SysException(RiskReturnEnum.DECRYPT_DATA_ERROR.getCode(), RiskReturnEnum.DECRYPT_DATA_ERROR.getText());
		}
		return result;
	}

	/**
	 * 上行返回响应结果---公钥解密
	 * @param arry
	 * @return
	 */
	private String decrypt1(String[] arry) {
		String result;
		try {
//			String[] arry = str.split("\\|");
			if (arry.length != 3) {
	//			return "0|" + DsCons.FORMAT_ERROR + "|" + Base64Utils.encode("数据格式错误".getBytes());
				throw new SysException(RiskReturnEnum.DATA_FORMAT_ERROR.getCode(), RiskReturnEnum.DATA_FORMAT_ERROR.getText());
			}
			// 解密第一段
			byte[] rsaUuidByte = Base64Utils.decode(arry[0]);
			String rsaUuidDecrypt = new String(rsaUuidByte, StandardCharsets.UTF_8);
			log.info("解密数据 riskShbankPublicKey {}",riskShbankPublicKey);
			String desKey = RSACoderUtils.decryptByPublicKey(rsaUuidDecrypt, riskShbankPublicKey);
			// 解密第二段
			byte[] baseDesTxtByte = Base64Utils.decode(arry[1]);
			byte[] newTxtByte = DesUtils.decrypt(baseDesTxtByte, desKey.getBytes());
//			String content = new String(newTxtByte, "UTF-8");
			result = new String(newTxtByte, StandardCharsets.UTF_8);
			// 解密第三段验证签名
			String newMd5Uuid = Md5Utils.md5ToHexStr(desKey);
			String newBase64Md5Uuid = Base64Utils.encode(newMd5Uuid.getBytes());
			if (!arry[2].equals(newBase64Md5Uuid)) {
				throw new SysException(RiskReturnEnum.CHECK_SIGN_ERROR.getCode(), RiskReturnEnum.CHECK_SIGN_ERROR.getText());
			}
		} catch (Exception e) {
			throw new SysException(RiskReturnEnum.DECRYPT_DATA_ERROR.getCode(), RiskReturnEnum.DECRYPT_DATA_ERROR.getText());
		}
		return result;
	}
    
    /**
     * 返回结果信息处理
     * @param shortCode
     * @param respCode
     * @param respMsg
     * @return
     */
	public String handleResult(String shortCode, String respCode, String respMsg){
    	return shortCode.concat("|").concat(respCode).concat("|").concat(Base64Utils.encode(respMsg.getBytes(Charset.defaultCharset())));
    }
    
    /**
     * 数据平台接口编号转换
     * @return
     */
	public static Map<String, String> enumConert() {
		Map<String, String> currEnumMap = new HashMap<>();
		currEnumMap.put(DataSourceCode.ANTI_FRAUD_BLACK.getCode(), "AntiFraudBlackListServiceImpl");
		currEnumMap.put(DataSourceCode.ANTI_FRAUD_FACTOR.getCode(), "AntiFraudFactorServiceImpl");
		currEnumMap.put(DataSourceCode.APPLY_RADAR.getCode(), "ApplyRadarServiceImpl");
		currEnumMap.put(DataSourceCode.BEHAVIOR_RADAR.getCode(), "ApplyRadarServiceImpl");
		currEnumMap.put(DataSourceCode.CID_SHIP.getCode(), "CidShipServiceImpl");
		currEnumMap.put(DataSourceCode.CIS_REPORT.getCode(), "CisReportService");
		currEnumMap.put(DataSourceCode.DISHONEST.getCode(), "DishonestServiceImpl");
		currEnumMap.put(DataSourceCode.GPS_SHIP.getCode(), "GpsShipServiceImpl");
		currEnumMap.put(DataSourceCode.JUXINLI_INFO.getCode(), "JuxinliInfoServiceImpl");
		currEnumMap.put(DataSourceCode.MAN_BANG_DATA.getCode(), "ManBangDataServiceImpl");
		currEnumMap.put(DataSourceCode.NET_WORK_STATE.getCode(), "NetworkStateServiceImpl");
		currEnumMap.put(DataSourceCode.NET_WORK_TIME.getCode(), "NetworkTimeServiceImpl");
		currEnumMap.put(DataSourceCode.OPERATOR_ELEMENT.getCode(), "OperatorElementServiceImpl");
		currEnumMap.put(DataSourceCode.OWNER_SHIP.getCode(), "OwnerShipServiceImpl");
		currEnumMap.put(DataSourceCode.TENG_XUN_YUN.getCode(), "TengxunYunServiceImpl");
		currEnumMap.put(DataSourceCode.TIAN_CHUANG.getCode(), "TianChuangInfoServiceImpl");
		currEnumMap.put(DataSourceCode.TONG_DUN_BLACK.getCode(), "DataTongDunBlackListServiceImpl");
		currEnumMap.put(DataSourceCode.WANDA_EDU_INFO.getCode(), "WandaEduInfoWsServiceImpl");
		currEnumMap.put(DataSourceCode.BAIDU_ADDRESS_SWITCH.getCode(), "BaiduAddressSwitchServiceImpl");
		currEnumMap.put(DataSourceCode.DATA_YOU_BEN.getCode(), "DataYouBenWsServiceImpl");
		currEnumMap.put(DataSourceCode.DATA_DIAN_HUA_BANG.getCode(), "DataDianHuaBangWsServiceImpl");
		currEnumMap.put(DataSourceCode.DATA_ZHI_CHENG_A_FU.getCode(), "DataZhiChengAfuScoreWsServiceImpl");
		currEnumMap.put(DataSourceCode.DATA_TAN_ZHI_INFO.getCode(), "DataTanZhiInfoWsServiceImpl");
		currEnumMap.put(DataSourceCode.DATA_TIAN_CHUANG_BLACK_LIST.getCode(), "DataTianChuangBlacklistWsServiceImpl");
		currEnumMap.put(DataSourceCode.BAI_RONG.getCode(), "BaiRongWsServiceImpl");
		return currEnumMap;
	}
	
	@SuppressWarnings("unchecked")
	public PropellingShDetailData getThirdCommonData(List<DataCallLogsBeanBO> reqList) {
		PropellingShDetailData propellingShDetailData = null;
		if (reqList != null && !reqList.isEmpty()){
			propellingShDetailData = new PropellingShDetailData();
			for (DataCallLogsBeanBO dataCall : reqList) {
				JSONObject jasonObject = JSONObject.parseObject(dataCall.getResult());
				switch (dataCall.getDataType()) {
				// 运营商入网时长数据
				case "11":
					if (null != jasonObject && "0000".equals(jasonObject.get("resCode"))) {
						propellingShDetailData.setNetTime(jasonObject.getString("netTime"));
					} 
					break;
				// 手机号码在网状态
				case "12":
					if ("0000".equals(jasonObject.get("resCode")) || "1001".equals(jasonObject.get("resCode")) ||
					    "1002".equals(jasonObject.get("resCode")) || "1003".equals(jasonObject.get("resCode")) ||
					    "1200".equals(jasonObject.get("resCode")) || "1202".equals(jasonObject.get("resCode")) ||
					    "1204".equals(jasonObject.get("resCode"))) {
						propellingShDetailData.setMobileState(jasonObject.getString("resCode"));
					} 
					break;
				//品友反欺诈 07
				case "07":

				case "02":
					if (null != jasonObject && ("0001".equals(jasonObject.get("resCode")) || 
							"0002".equals(jasonObject.get("resCode")))) {
						propellingShDetailData.setAlternateField4(jasonObject.getString("resMsg"));
					} 
					break;
				// 逾期催收黑名单(小视催收黑名单)
				case "01":
					if (null != jasonObject && "0000".equals(jasonObject.get("resCode"))) {
						JSONArray jsonArray = (JSONArray) jasonObject.get("resData");
						propellingShDetailData.setAlternateField5(String.valueOf(jsonArray.size()));
					} 
					break;
				//腾讯云
				case "15":
					if (null != jasonObject && "0000".equals(jasonObject.get("resCode"))) {
						JSONObject data = JSONObject.parseObject(jasonObject.getString("data"));
						int riskScore = (Integer)data.get("riskScore");
						propellingShDetailData.setTengxunYunRiskScore(riskScore);
					} 
					break;
				//同盾(被有本替换)
				case "20":
					final String RISK_NAME_1="身份证格式校验错误";
					final String RISK_NAME_2="身份证不是二代身份证";
					final String RISK_NAME_3="身份证命中法院失信名单";
					final String RISK_NAME_4="身份证命中犯罪通缉名单";
					final String RISK_NAME_5="身份证命中法院执行名单";
					final String RISK_NAME_6="身份证命中信贷逾期名单";
					final String RISK_NAME_7="身份证命中高风险关注名单";
					final String RISK_NAME_8="身份证命中车辆租赁违约名单";
					final String RISK_NAME_9="身份证命中欠款公司法人代表名单";
					final String RISK_NAME_10="身份证命中欠税公司法人代表名单";
					final String RISK_NAME_11="手机号命中信贷逾期名单";
					final String RISK_NAME_12="手机号命中欠款公司法人代表名单";
					if (null != jasonObject && "0000".equals(jasonObject.get("resCode"))) {
						String resData = jasonObject.getString("resData");
						JSONObject resultDesc = JSONObject.parseObject(resData);
						JSONObject antifraud = resultDesc.getJSONObject("ANTIFRAUD");
						Integer score = antifraud.getInteger("final_score");
						propellingShDetailData.setTdScore(score);
						List<Object> riskDetailList = JSONObject.parseArray(antifraud.getString("risk_items"));
						for (Object obj : riskDetailList) {
							Map<String, Object> map = (Map<String, Object>) obj;
							Object riskDetail = map.get("risk_detail");
							String res111 = JSONObject.toJSONString(riskDetail);
							List<Object> list2  = JSONObject.parseArray(res111);
							for (Object obj2 : list2) {
								Map<String, Object> map2 = (Map<String, Object>) obj2;
								if (map2.get("description") != null){
									String aa = String.valueOf(map2.get("description"));
									if(RISK_NAME_1.equals(aa)){
										propellingShDetailData.setRiskName1(aa);
									}
									if(RISK_NAME_2.equals(aa)){
										propellingShDetailData.setRiskName2(aa);
									}
									if(RISK_NAME_3.equals(aa)){
										propellingShDetailData.setRiskName3(aa);
									}
									if(RISK_NAME_4.equals(aa)){
										propellingShDetailData.setRiskName4(aa);
									}
									if(RISK_NAME_5.equals(aa)){
										propellingShDetailData.setRiskName5(aa);
									}
									if(RISK_NAME_6.equals(aa)){
										propellingShDetailData.setRiskName6(aa);
									}
									if(RISK_NAME_7.equals(aa)){
										propellingShDetailData.setRiskName7(aa);
									}
									if(RISK_NAME_8.equals(aa)){
										propellingShDetailData.setRiskName8(aa);
									}
									if(RISK_NAME_9.equals(aa)){
										propellingShDetailData.setRiskName9(aa);
									}
									if(RISK_NAME_10.equals(aa)){
										propellingShDetailData.setRiskName10(aa);
									}
									if(RISK_NAME_11.equals(aa)){
										propellingShDetailData.setRiskName11(aa);
									}
									if(RISK_NAME_12.equals(aa)){
										propellingShDetailData.setRiskName12(aa);
									}
								}
							}
						}
					}
					break;
				// 新颜征信申请雷达评分(申请准入分)	
				case "03":
					if (null != jasonObject && "0000".equals(jasonObject.get("resCode"))) {
							JSONObject resData=(JSONObject) jasonObject.get("resData");
				            String applyScore= resData.getString("apply_score");
				            propellingShDetailData.setAlternateField6(applyScore);
						} 
					break;
				// 新颜征信行为雷达评分(贷款行为分)	
				case "04":
					if (null != jasonObject && "0000".equals(jasonObject.get("resCode"))) {
							JSONObject resData=(JSONObject) jasonObject.get("resData");
				            Integer loansScore= Integer.valueOf(resData.getString("loans_score"));
				            propellingShDetailData.setAlternateField7(String.valueOf(loansScore));
					}  
					break;
				//天创生活探针--多头借贷反欺诈分
				case "16":
					if (null != jasonObject && "0000".equals(jasonObject.get("resCode"))) {
						JSONObject resData = (JSONObject) jasonObject.get("resData");
			            Double scoreTotal = Double.valueOf(resData.getString("score_total"));
			            propellingShDetailData.setAlternateField8(String.valueOf(scoreTotal));
					} 
					break;
				//聚信立蜜罐分--灰度分-基于社交网络的综合风险评估-取值(0-100)
				case "09":
					if (null != jasonObject && "0000".equals(jasonObject.get("resCode"))) {
						JSONObject resData = (JSONObject) jasonObject.get("resData");
						Object phone_gray_score = resData.get("phone_gray_score");
						propellingShDetailData.setAlternateField9(String.valueOf(phone_gray_score));
					} 
					break;

					default:
						throw new IllegalStateException("Unexpected value: " + dataCall.getDataType());
				}
			}
		}
		return propellingShDetailData;
	}
	
	@GetMapping("/serverStatus")
	public String serverStatus(){
		return "service is running";
	}
	
	@GetMapping("/deleteRedisKey")
	public String deleteRedisKey(){
		log.info(">>>>>>>>>>>>>>>redis中自然流量订单统计:{}", redisUtil.get(RedisKey.CUST_TYPE_CODE_KEY + "FLOW022"));
		log.info("=============start 清理redis中自然流量统计=============");
		boolean isYes = redisUtil.hasKey(RedisKey.CUST_TYPE_CODE_KEY + "FLOW022");
		if (isYes) {
			redisUtil.del(RedisKey.CUST_TYPE_CODE_KEY + "FLOW022");
		} else {
			log.info("缓存中没有找到 key：{}" , RedisKey.CUST_TYPE_CODE_KEY + "FLOW022");
		}
		log.info("=============end 清理redis中自然流量统计=============");
		return RedisKey.CUST_TYPE_CODE_KEY + "FLOW022 已删除";
	}
	
	@RequestMapping(value = "/changeRedis", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")
	public String changeRedis(@RequestBody(required=false) String reqData){
		System.out.println("==========redis:" + redisUtil.get(RedisKey.CUST_TYPE_CODE_KEY + "FLOW022"));
		Map<String, Object> map1 = new HashMap<String, Object>();
		map1.put("FLOW022", reqData);
		redisUtil.set(RedisKey.CUST_TYPE_CODE_KEY + "FLOW022", map1);
		System.out.println("==========redis:" + redisUtil.get(RedisKey.CUST_TYPE_CODE_KEY + "FLOW022"));
		return String.valueOf(redisUtil.get(RedisKey.CUST_TYPE_CODE_KEY + "FLOW022"));
	}
	
    
}